﻿using LiteBlog.Common.Entities;
using LiteBlog.Components.Contracts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LiteBlog.Components.Helpers
{
    internal class DocumentHelper
    {
        // Remove documents from the docs folder which are present in deletePost, but not in existPost
        internal static void DeleteAttachments(IDocumentComp component, Post existPost, Post deletePost)
        {
            foreach (var document in deletePost.Documents)
            {
                bool removed = existPost
                    .Documents
                    .SingleOrDefault(d => d.Id == document.Id) == null;
                if (removed)
                {
                    component.Remove(document.Id);
                }
            }
        }
    }
}
